class myEventEmitter{
  constructor(){
    this.eventMap={}
  }

  on(type,handler){
    if(!(handler instanceof Function)){
      throw new Error('哥，你错了 请传一个函数') 
    }
    if(!this.eventMap[type]){
      this.eventMap[type]=[]
    }
    this.eventMap[type].push(handler)
  }

  emit(type,params){
    if(this.eventMap[type]){
      this.eventMap[type].forEach((handler,index)=>{
        handler(params)
      })
    }
  }

  off(type,handler){
    if(this.eventMap[type]){
      this.eventMap[type].splice(this.eventMap[type].indexOf(handler)>>>0,1)
    }
  }
}

const myEvent=new myEventEmitter();
console.log(myEvent);
const testHandler=function(params){
  console.log(`test事件被触发了，testHandler接收到的入参数${params}`);
}

myEvent.on('test',testHandler)
console.log(myEvent);
myEvent.emit('test','漂亮惠妹')